package com.kehongborui.spring;

import com.kehongborui.empmanagesys.dao.UserDao;
import com.kehongborui.empmanagesys.entity.User;

import java.sql.SQLException;

/**
 * @author zhang peng yang ming
 * @create 2018-07-29 20:52
 */
public class LoginService {
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     *  用户登陆
     * @param username
     * @param password
     * @return
     */
    public User login(String username, String password) {
        try {
            User user = userDao.findByUsername(username);
            if (user != null && password.equals(user.getPassword())) {
                return user;
            }
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
        return null;
    }
}
